$(function () {
    $.ajax(baseUrl + "/slides", {
        success: function (res) {
            let length = res.length
            for (let i = 0; i < length - 1; i++) {
                $(".cursor").append("<span></span>")
            }
            const newHtml = template("swipe-temp", {
                swipeList: res,
                baseUrl: baseUrl,
            })
            $(".swipe-wrapper").append(newHtml)
            var swiper = Swipe(document.querySelector(".swipe"), {
                auto: 3000,
                transitionEnd: function (index) {
                    // index++;
                    $(".cursor span")
                        .eq(index)
                        .addClass("active")
                        .siblings(".active")
                        .removeClass("active")
                },
            })

            // 上/下一张
            $(".swipe .arrow").on("click", function () {
                var _this = $(this)

                if (_this.is(".prev")) {
                    swiper.prev()
                } else if (_this.is(".next")) {
                    swiper.next()
                }
            })
        },
        error: function (err) {
            console.log("err:", err)
        },
    })
})
